﻿<div class="btn-toolbar">
    @{
        int pageCount = (int)ViewData["pagecount"];
        int pageSize = (int)ViewData["pagesize"];
        int pageIndex = (int)ViewData["pageindex"];
        string urlFormat = string.Format("/{0}/{1}?pagesize={{0}}&pageindex={{1}}"
            , Request.RequestContext.RouteData.Values["controller"]
            , Request.RequestContext.RouteData.Values["action"]);
        var maxLength = pageCount < 5 ? pageCount : 5;
    }
    @if (pageCount > 1)
    {
        <div class="btn-group">
            @for (int i = 1; i <= maxLength; i++)
            {
                var url = string.Format(urlFormat, pageSize, i);
                <a class="btn" href="@url">@i</a>
            }
        </div>
    }
    @if (maxLength < pageCount)
    {
        <div class="btn-group">
            <button class="btn">GO</button>
            <button class="btn dropdown-toggle" data-toggle="dropdown">
                <span class="caret"></span>
            </button>
            <ul class="dropdown-menu">
                @for (int i = 1; i <= pageCount; i++)
                {
                    var url = string.Format(urlFormat, pageSize, i);
                    <li><a href="@url">@i</a></li>
                }
            </ul>
        </div>
    }
</div>
